package org.cloud.service.Impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.cloud.mapper.PayMapper;
import org.cloud.model.dto.PayDto;
import org.cloud.model.entity.Pay;
import org.cloud.service.IPayService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * ClassName: PayServiceImpl
 * Package: org.cloud.service.Impl
 * Description:
 *
 * @Author: @weixueshi
 * @Create: 2024/4/10 - 21:31
 * @Version: v1.0
 */
@Service
public class PayServiceImpl extends ServiceImpl<PayMapper, Pay> implements IPayService {

    @Override
    public void addPayment(PayDto payDto) {
        Pay pay = new Pay();
        pay.setUserId(payDto.getUserId());
        pay.setPayNo(payDto.getPayNo());
        pay.setOrderNo(payDto.getOrderNo());
        this.save(pay);
    }

    @Override
    public List<PayDto> queryOrder(String orderNo) {
        QueryWrapper<Pay> wrapper = new QueryWrapper<>();
        wrapper.eq("order_no", orderNo);
        List<Pay> pays = baseMapper.selectList(wrapper);
        List<PayDto> list = new ArrayList<>();
        pays.stream().forEach(pay ->{
            PayDto payDto = new PayDto();
            BeanUtils.copyProperties(pay, payDto);
            list.add(payDto);
        });
        return list;
    }
}
